package com.hc.serviceImpl;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import com.hc.bean.GradeBean;
import com.hc.comm.Service.ComparatorGradeBeanl;
import com.hc.comm.Service.CreateSimpleExcelToDisk;
import com.hc.dao.RunSqlDao;
import com.hc.daoImpl.RunSqlDaoImpl;
import com.hc.excel.util.CreateALLDataToExcelToDisk;
import com.hc.excel.util.CreateCompanyGradeExcelToDisk;
import com.hc.excel.util.CreateDownFileTestExcelToDisk;
import com.hc.excel.util.CreateVlanGradeExcelToDisk;
import com.hc.excel.util.CreateWebTestExcelToDisk;
import com.hc.service.CompanyGradeService;
import com.hc.service.ExportReportService;
import com.hc.service.GetDataService;
import com.hc.service.VlanGradeService;
import com.hc.util.DateUtil;
import com.hc.util.DateUtilExt;

public class ExportReportServiceImpl implements ExportReportService{

	
	public final static int pageCount = 18;
	
	@Override
	public String getRawData(String selectRawTestType,String companySelect,String startDate ,String stopDate,int pageNumber,String companyText) {
	
	
		GetDataService service = new GetDataServiceImpl();
		List list = service.getRawData(selectRawTestType, companySelect, startDate, stopDate, pageNumber,companyText);
		
		
		if(pageNumber==1){
			
			list.remove(list.size()-1);
		}
		
		String msg ="";
		if(list!=null){
			
			String fialeName= System.currentTimeMillis()+"";
			
			
			if("网页测试".equals(selectRawTestType)){
				
				
				CreateWebTestExcelToDisk.CreateWebTestExcel(list, fialeName,startDate, stopDate);
				
			}else{
				
				CreateDownFileTestExcelToDisk.CreateDownFileTestExcel(list, fialeName,startDate, stopDate);
			}
			
			

			msg =fialeName;
			
		}else{
			
			msg = "false";
		}
		return msg;

		
	}





	@Override
	public String getGradeData(String startDate,String stopDate) {

	
		GetDataService service = new GetDataServiceImpl();
		List list = service.getGradeData(startDate, stopDate);
		
		String msg="";
		if(list!=null&&list.size()>0){
			
			
			String fileName = System.currentTimeMillis()+"";
			
			
			msg =fileName ;
			
			CreateCompanyGradeExcelToDisk.createCompanyGradeExcel(list, fileName, startDate, stopDate);
			
//			CreateSimpleExcelToDisk.createGradeExcel(list, fileName, "公司");
			
			
			
		}else{
			
			msg = "false";
			
		}
		
		return msg;

	}
	
	
	

	@Override
	public String getVlanGradeData(String startDate,String stopDate ,String vlanGradeCompanyTextSelect,String vlanGradeCompanyText) {

		GetDataService service = new GetDataServiceImpl();
		List list = service.getVlanGradeData(startDate, stopDate,vlanGradeCompanyTextSelect,vlanGradeCompanyText);

		String msg="";
		if(list!=null&&list.size()>0){
			
			
			String fileName = System.currentTimeMillis()+"";
			
			
			msg =fileName ;
			
			CreateVlanGradeExcelToDisk.createVlanGradeExcel(list, fileName, startDate, stopDate);
			
//			CreateSimpleExcelToDisk.createGradeExcel(list, fileName, "vlan");
			
			
			
		}else{
			
			msg = "false";
			
		}
		
	return msg;
	}





	@Override
	public String getAllData(String startDate, String stopDate) {
	
		GetDataService service = new GetDataServiceImpl();
		List webList = service.getRawData("网页测试", "所有", startDate, stopDate, 1,"");
		webList.remove(webList.size()-1);
		List downFileList = service.getRawData("下载测试", "所有", startDate, stopDate, 1,"");
		downFileList.remove(downFileList.size()-1);
		List companyList = service.getGradeData(startDate, stopDate);
		List vlanList = service.getVlanGradeData(startDate, stopDate,"所有","");
		
		
		Map<String,List> map = new HashMap<String,List>();
		
		map.put("webTest", webList);
		map.put("downFileTest", downFileList);
		map.put("company", companyList);
		map.put("vlan", vlanList);
		
		String msg="";
		if(map.size()>0){
			
			
			String fileName = System.currentTimeMillis()+"";
			
			
			msg =fileName ;
			
			CreateALLDataToExcelToDisk.createALLDataToExcel(map, fileName, startDate, stopDate);
			
		}else{
			
			msg = "false";
			
		}
		
		
		
		
		return msg;
	}



}
